class_name Equipment
extends Node2D

var equipment_name: String

var equipment_owner

@onready var asc: AbilitySystemComponent = %AbilitySystemComponent

@onready var animator: AnimatedSprite2D = %Animator


func on_attach(target: AbilitySystemComponent) -> void:
	asc.logic_owner = target.get_parent()
	
	equipment_owner = target.get_parent()
	equipment_owner.grant_abilities(asc.ability_assets)

	_on_attach(target)


func on_detach(target: AbilitySystemComponent) -> void:
	_on_detach(target)
	
	equipment_owner.remove_abilities(asc.ability_assets)
	equipment_owner = null
	
	asc.logic_owner = null


#region Need to override
func _on_attach(_target: AbilitySystemComponent) -> void:
	pass


func _on_detach(_target: AbilitySystemComponent) -> void:
	pass
#endregion


#region Helper Functions
#region Animator
func play_animation(animation_name: String) -> void:
	animator.play(animation_name)


func stop_animation() -> void:
	animator.stop()
#endregion


#region Gameplay Attribute 
func get_attribute(attribute_name: String) -> GameplayAttribute:
	return asc.attribute_set.get_attribute(attribute_name)
#endregion


#region Gameplay Tag
func add_tag(tag: String) -> void:
	asc.tag_manager.add_tag(tag)


func add_tags(tags: Array[String]) -> void:
	asc.tag_manager.add_tags(tags)


func remove_tag(tag: String) -> void:
	asc.tag_manager.remove_tag(tag)


func remove_tags(tags: Array[String]) -> void:
	asc.tag_manager.remove_tags(tags)


func has_tag(tag: String) -> bool:
	return asc.tag_manager.has_tag(tag)


func has_any_tags(tags: Array[String]) -> bool:
	return asc.tag_manager.has_any_tags(tags)


func has_all_tags(tags: Array[String]) -> bool:
	return asc.tag_manager.has_all_tags(tags)


func get_all_tags() -> Array[String]:
	return asc.tag_manager.get_all_tags()
#endregion


#region Gameplay Ability
func grant_ability(ability_asset: GameplayAbilityAsset) -> void:
	asc.ability_manager.grant_ability(ability_asset)


func try_apply_ability(ability_asset: GameplayAbilityAsset, target: AbilitySystemComponent) -> void:
	asc.ability_manager.try_apply_ability(ability_asset, target)


func try_apply_ability_by_name(ability_name: String, target: AbilitySystemComponent) -> void:
	asc.ability_manager.try_apply_ability_by_name(ability_name, target)


func try_apply_ability_to_self(ability_asset: GameplayAbilityAsset) -> void:
	try_apply_ability(ability_asset, asc)


func remove_ability(ability_asset: GameplayAbilityAsset) -> void:
	asc.ability_manager.remove_ability(ability_asset)


func activate_ability(ability_asset: GameplayAbilityAsset) -> void:
	asc.ability_manager.activate_ability(ability_asset)
	

func deactivate_ability(ability_asset: GameplayAbilityAsset) -> void:
	asc.ability_manager.deactivate_ability(ability_asset)
#endregion
#endregion
